package net.cyue.easyconfiguration.api;

import net.cyue.easyconfiguration.node.NodeType;

import java.util.List;
import java.util.Map;

public interface IConfigurationResource {

    NodeType getNodeType(String path);
    /**
     * 获取 table 键名列表
     * @param tablePath table的路径
     * @return 对于 tablePath = * 或 空值 返回 所有一级 key， tablePath = a 返回 a.* 中的 *
     */
    List<String> getTableKeyList(String tablePath);

    Object get(String path);
    default Object get(String path, Object defaultValue) {
        Object v = get(path);
        return v == null ? defaultValue : v;
    };
    String getString(String path);
    default String getString(String path, String defaultValue) {
        String v = getString(path);
        return v == null ? defaultValue : v;
    };
    Number getNumber(String path);
    default Number getNumber(String path, Number defaultValue) {
        Number v = getNumber(path);
        return v == null ? defaultValue : v;
    };
    Boolean getBoolean(String path);
    default Boolean getBoolean(String path, Boolean defaultValue) {
        Boolean v = getBoolean(path);
        return v == null ? defaultValue : v;
    };
    Object[] getArray(String path);
    default Object[] getArray(String path, Object[] defaultValue) {
        Object[] v = getArray(path);
        return v == null ? defaultValue : v;
    };
    Map<String, Object> getTable(String path);
    default Map<String, Object> getTable(String path, Map<String, Object> defaultValue) {
        Map<String, Object> v = getTable(path);
        return v == null ? defaultValue : v;
    };
}
